package com.itheima.mybigdecimal;


import java.math.BigDecimal;
import java.util.Scanner;

/**
 * @Author 王加鑫
 * @Date 2021/5/10 11:28
 * @Version 1.0
 */
public class BigDecimalTest {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        lo:while (true){
            System.out.println("请输入要运算的第一个数:");
            String num1 = sc.next();
            System.out.println("请输入要运算的第二个数:");
            String num2 = sc.next();
            BigDecimal b1 = new BigDecimal(num1);
            BigDecimal b2 = new BigDecimal(num2);
            System.out.println("请输入要进行的运算操作[1:加法 2:减法 3:乘法 4:除法]");
            String choice = sc.next();
            switch (choice){
                case "1":
                    System.out.println(b1.add(b2));
                    break;
                case "2":
                    System.out.println(b1.subtract(b2));
                    break;
                case "4":
                    System.out.println(b1.divide(b2,8,BigDecimal.ROUND_HALF_UP));
                    break;
                case "3":
                    System.out.println(b1.multiply(b2));
                    break;
                case "5":
                    break lo;
                default:
                    System.out.println("您的输入有误");
                    break;
            }
        }
    }
}
